﻿#region << 文件说明 >>

/*----------------------------------------------------------------
 * 命名空间：Vampirewal.Core.FlowEngine.Internal
 * 唯一标识：459a6fe2-dbf4-45b8-b1da-824de0e2965b
 * 文件名：VampirewalFlowLinkOption
 *
 * 创建者：杨程
 * 电子邮箱：235160615@qq.com
 * 创建时间：2023/10/27 17:36:19
 * 版本：V1.0.0
 * 描述：
 *
 * ----------------------------------------------------------------
 * 修改人：
 * 时间：
 * 修改说明：
 *
 * 版本：V1.0.1
 *----------------------------------------------------------------*/

#endregion << 文件说明 >>

namespace Vampirewal.Core.FlowEngine;

/// <summary>
/// 流程引擎连线配置器
/// </summary>
internal class VampirewalFlowLinkOption : IVampirewalFlowLinkOption
{
    public Flow FlowInfo { get; set; }

    public FlowLink Link { get; set; }

    public List<FlowUnit> Units { get; set; }

    public VampirewalFlowLinkOption(List<FlowUnit> _Units, Flow flowInfo)
    {
        Link = new FlowLink()
        {
            FlowId = flowInfo.BillId,
            DtlId = Guid.NewGuid().ToString(),
        };

        Units = _Units;
        FlowInfo = flowInfo;
    }

    /// <summary>
    /// 设置上一级ID
    /// </summary>
    /// <param name="PreviousUnitIndex"></param>
    /// <returns></returns>
    public IVampirewalFlowLinkOption SetPreviousUnitIndex(int PreviousUnitIndex)
    {
        var Previous = Units.FirstOrDefault(f => f.UnitIndex == PreviousUnitIndex);

        if (Previous == null)
        {
            throw new Exception($"上一级节点序号:{PreviousUnitIndex},未找到！");
        }

        Link.PreviousUnitId = Previous.DtlId;

        return this;
    }

    /// <summary>
    /// 设置连接条件
    /// </summary>
    /// <param name="Condition">连接条件</param>
    /// <returns></returns>
    public IVampirewalFlowLinkOption SetCondition(string Condition)
    {
        Link.Condition = Condition;
        return this;
    }
}